package com.apress.prospring.ch5;

import com.apress.prospring5.ch5.SimpleAdvice;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

public class RegexPointcutDemo {
    public static void main(String[] args) {
        Guitarist johnMayer=new Guitarist();

        JdkRegexpMethodPointcut pc=new JdkRegexpMethodPointcut();
        pc.setPattern(".*sing.*");
        Advisor advisor=new DefaultPointcutAdvisor(pc,new SimpleAdvice());
        ProxyFactory pf=new ProxyFactory();
        pf.setTarget(johnMayer);
        pf.addAdvisor(advisor);
        Guitarist proxy=(Guitarist) pf.getProxy();
        proxy.sing();
        proxy.sing2();
        proxy.rest();
    }
}
